﻿using Appliaction.Dto.Sinv;
using Appliaction.IAppServices.Sinv;
using AutoMapper;
using Domain.Entitys.Sinv;
using Domain.IRepositorys.Sinv;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Appliaction.AppServices.Sinv
{
    public class Sinv_CustomerService : ISinv_CustomerService
    {
        private readonly ISinv_CustomerRepository sinv_CustomerRepository;
        private readonly IMapper mapper;

        public Sinv_CustomerService(ISinv_CustomerRepository sinv_CustomerRepository,IMapper mapper)
        {
            this.sinv_CustomerRepository = sinv_CustomerRepository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 条件分页查询客户信息
        /// </summary>
        /// <param name="name"></param>
        /// <param name="phone"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public async Task<List<Sinv_Customer>> GetSinv_CustomerAsync(string name, string phone, int currentPage, int pageSize)
        {
            return await sinv_CustomerRepository.GetSinv_CustomerAsync(name, phone, currentPage, pageSize);
        }

        /// <summary>
        /// 条件查询客户总数
        /// </summary>
        /// <param name="name"></param>
        /// <param name="phone"></param>
        /// <returns></returns>
        public async Task<int> GetSinv_CustomerCountAsync(string name, string phone)
        {
            return await sinv_CustomerRepository.GetSinv_CustomerCountAsync(name, phone);
        }

        /// <summary>
        /// 逻辑删除客户信息
        /// </summary>
        /// <param name="sinv_CustomerDelDto"></param>
        /// <returns></returns>
        public async Task<int> Sinv_CustomerDelAsync(Sinv_CustomerDelDto sinv_CustomerDelDto)
        {
            Sinv_Customer sinv_Customer = mapper.Map<Sinv_Customer>(sinv_CustomerDelDto);
            return await sinv_CustomerRepository.Sinv_CustomerDelAsync(sinv_Customer);
        }

        /// <summary>
        /// 添加客户信息
        /// </summary>
        /// <param name="sinv_CustomerAddDto"></param>
        /// <returns></returns>
        public async Task<int> Sinv_CustomerAddAsync(Sinv_CustomerAddDto sinv_CustomerAddDto)
        {
            Sinv_Customer sinv_Customer = mapper.Map<Sinv_Customer>(sinv_CustomerAddDto);
            return await sinv_CustomerRepository.Sinv_CustomerAddAsync(sinv_Customer);
        }

        /// <summary>
        /// 根据客户编号查询对应客户信息
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public async Task<Sinv_Customer> Sinv_CustomerByCodeAsync(string code)
        {
            return await sinv_CustomerRepository.Sinv_CustomerByCodeAsync(code);
        }

        /// <summary>
        /// 修改部门信息
        /// </summary>
        /// <param name="sinv_CustomerUpdateDto"></param>
        /// <returns></returns>
        public async Task<int> Sinv_CustomerUpdateAsync(Sinv_CustomerUpdateDto sinv_CustomerUpdateDto)
        {
            Sinv_Customer sinv_Customer = mapper.Map<Sinv_Customer>(sinv_CustomerUpdateDto);
            return await sinv_CustomerRepository.Sinv_CustomerUpdateAsync(sinv_Customer);
        }

        /// <summary>
        /// 根据客户名称查询客户信息
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public async Task<List<Sinv_Customer>> Sinv_CustomerByNameAsync(string name)
        {
            return await sinv_CustomerRepository.Sinv_CustomerByNameAsync(name);
        }
    }
}
